package com.NeuglsWorkStudio.UI.FormElement.Component
{
	import com.NeuglsWorkStudio.Colors.ColorUtility;
	import com.NeuglsWorkStudio.Colors.HSL;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TConfig;
	import com.NeuglsWorkStudio.UI.FormElement.Config.TEditConfig;
	
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;

	public class TEdit extends TCustomEdit
	{
		private var _FInputBox:TextField;
		private var _FATextFormat:TextFormat;
		private var _FEnabled:Boolean=true;
		private var _FRestrict:String=null;
		
		public function TEdit(AConfig:TConfig)
		{
			super(AConfig);
		}
		
		
		public function get Restrict():String
		{
			return _FRestrict;
		}

		public function set Restrict(value:String):void
		{
			_FRestrict = value;
			_FInputBox.restrict=value;
		}

		public function get Enabled():Boolean
		{
			return _FEnabled;
		}

		public function set Enabled(value:Boolean):void
		{
			_FEnabled = value;
			
			EnabledChanged();
		}

		public function get ATextFormat():TextFormat
		{
			return _FATextFormat;
		}

		public function set ATextFormat(value:TextFormat):void
		{
			_FATextFormat = value;
			_FInputBox.setTextFormat(value);
		}

		public function GetEditConfig():TEditConfig{
			return _FConfig as TEditConfig;
		}
		
		override protected function Init():void{
			super.Init();
			
			_FATextFormat=new TextFormat("Tahoma",14,ColorUtility.GetColorFromBaseColor(GetEditConfig().BaseColor));
			
			_FInputBox=new TextField();
			_FInputBox.defaultTextFormat=_FATextFormat;
			this.Enabled=GetEditConfig().Enabled;
			_FInputBox.width=_FConfig.Width;
			_FInputBox.height=_FConfig.Height;
			_FInputBox.border=GetEditConfig().DisplayBorder;
			_FInputBox.borderColor=ColorUtility.GetColorFromBaseColor(GetEditConfig().BaseColor);
			_FInputBox.text=GetEditConfig().Text;
			Restrict=GetEditConfig().Restrict;
			this.addChild(_FInputBox);
		}
		
		override protected function SetText(val:String):void{
			_FInputBox.text=val;
		}
		
		override protected function GetText():String{
			return _FInputBox.text;
		}
		
		protected function EnabledChanged():void{
			_FInputBox.type=_FEnabled?TextFieldType.INPUT:TextFieldType.DYNAMIC;
		}
		
		protected function get Editor():TextField{
			return _FInputBox;
		}
	}
}